$(function () {
    // 将获取到的当前年份设置到 HTML 元素中 ，footer中用到
    document.getElementById("currentYear").textContent = new Date().getFullYear();

    //调整导航条的激活状态
    const currentPath = window.location.pathname;

    $('#navbar a').each(function () {
        if ($(this).attr('href') === currentPath) {
            $(this).addClass('active');
        }
    });
})

function formDataToJson(formElement) {
    const formData = {};
    const formFields = $(formElement).serializeArray();
    $.each(formFields, function (i, field) {
        if (field.value !== undefined && field.value !== "") {
            formData[field.name] = field.value;
        }
    });
    return formData;
}